package org.example.chat.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

@Component
public class TestJob {

    @XxlJob("TestBeanModeJob")
    public void testBeanMode() {
        System.out.println("1111");
    }

    public void testGlueMode() {
        System.out.println("2222");
    }

    @XxlJob("TestJobSharding")
    public void testSharding() {
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        System.out.println("index：" + shardIndex);
        System.out.println("total：" + shardTotal);
        long begin = System.currentTimeMillis();
        for (int i = 0; i < 20; i++) {
            if (i % shardTotal == shardIndex) {
                try {
                    Thread.sleep(1000);
                    System.out.println("任务" + i + "执行");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("耗时：" + (System.currentTimeMillis() - begin));
    }

    @XxlJob("TestJobParam")
    public void testJobParam() {
        System.out.println(XxlJobHelper.getJobParam());
    }
}
